package com.mine.frame.mylandemo.ui.dialog

import android.app.AlertDialog
import android.content.Context
import android.os.Bundle
import android.text.TextUtils
import com.blankj.utilcode.util.ClickUtils
import com.blankj.utilcode.util.ToastUtils
import com.mine.frame.mylandemo.R
import kotlinx.android.synthetic.main.dialog_create_name.*

/**
 * @Date 2022/6/15
 * Description:
 */
class CreateNameDialog (context: Context) : AlertDialog(context) {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.dialog_create_name )
        setCanceledOnTouchOutside(false)
    }


    fun setBtnClickListener(listener : (CharSequence) -> Unit){
        ClickUtils.applySingleDebouncing(arrayOf(btnCancel ,btnSure)){
            when(it.id){
                R.id.btnCancel ->{
                    this.dismiss()
                }
                R.id.btnSure ->{
                    if (TextUtils.isEmpty(edtName.text)){
                        ToastUtils.showShort("请输入名称")
                    }else{
                        this.dismiss()
                        val name = edtName.text
                        listener(name)
                    }
                }
            }
        }
    }
}